request audio focus when recording voice messages#6194
request audio focus when recording voice messages#6194bmarty merged 5 commits intoelement-hq:developfrom
Conversation
Signed-off-by: vmfunc <celeste@linux.com>
|
Thank you for your contribution! Here are a few things to check in the PR to ensure it's reviewed as quickly as possible:
|
bmarty
left a comment
There was a problem hiding this comment.
Thanks for the PR. Looks good, if you have time to check what's happening when the audio focus is lost while recording a voice message, that would be awesome.
|
|
||
| private fun CoroutineScope.startRecording() = launch { | ||
| try { | ||
| audioFocus.requestAudioFocus(AudioFocusRequester.VoiceMessage) {} |
There was a problem hiding this comment.
In the case of a voice recording, willPausedWhenDucked should maybe return false?
Maybe create a new AudioFocusRequester.RecordVoiceMessage to handle this case.
Also the second parameter onFocusLost should maybe do something like stopping the recording?
Maybe worth checking the behavior when a voice message is getting recorded and an audio stream is (re)started (from a notification for instance).
There was a problem hiding this comment.
yeah good call on all of these, pushed two more commits.
added RecordVoiceMessage as a separate requester with willPausedWhenDucked = false - no audio output to duck when recording, and this way notification sounds won't trigger transient focus loss and kill the recording. only actual focus loss (phone call etc) stops it.
onFocusLost now finishes the recording and leaves the partial result in preview state so nothing gets lost.
haven't tested the notification audio restart on device yet but with willPausedWhenDucked = false those events shouldn't reach us at all.
separates recording from playback focus - willPausedWhenDucked is false for recording so notification sounds don't interrupt mid-recording Signed-off-by: vmfunc <celeste@linux.com>
if something else grabs focus mid-recording (phone call, etc), stop the recording and keep the partial result in preview state instead of silently recording garbage Signed-off-by: vmfunc <celeste@linux.com>
...ries/audio/impl/src/main/kotlin/io/element/android/libraries/audio/impl/DefaultAudioFocus.kt
Outdated
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #6194 +/- ##
===========================================
- Coverage 81.41% 81.41% -0.01%
===========================================
Files 2569 2569
Lines 69701 69711 +10
Branches 8942 8942
===========================================
+ Hits 56750 56754 +4
- Misses 9630 9637 +7
+ Partials 3321 3320 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
per review feedback - need true here so the onFocusLost callback actually fires on all Android versions Signed-off-by: vmfunc <celeste@linux.com>
|
hey @bmarty seems ready for review - codecov fails but after digging i doubt it comes from my end |
|
sorry for bumping this. any issues with this PR? |
Sorry for the delay, I was off last week. Thanks again for the PR! |
|
all good, thank you! |
recording a voice message now requests audio focus; background media
(spotify, deezer, etc.) gets paused while recording and resumes when
you stop. matches the behavior of signal and whatsapp.
the AudioFocus infrastructure was already in place for playback
(DefaultMediaPlayer uses it), just wasn't wired into the recording path.
fixes #5997